package com.leetcode_Onequestion;

/**
 * @Author jsh
 * @Date 2022/4/14 21:08
 * @Version 1.0
 */
/*
* 爱吃香蕉的珂珂
* */
public class leetcode_875 {

    public static int minEatingSpeed(int[] piles, int H) {
        int eatmin = 1;
        int hi = 100000;

        while ( eatmin <  hi){
            int mid =  (eatmin +hi) /2;
            if (!possible(piles,H,mid))
                eatmin = mid + 1;
            else
                hi = mid;
        }
        return eatmin;
    }

    private static boolean possible(int[] piles, int h, int mid) {
        int time = 0;
        for (int pile : piles) {
            time += (pile-1) / mid +1;
        }
        return time <=h;
    }
}
